package com.yricky.nep.mm;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class UsageView extends View {
    private String usage="0,1024s0,984s1004,20";
    private float start;
    private float size;
    Paint paint=new Paint();
    public UsageView(Context context) {
        super(context);
    }

    public UsageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setUsage(String usage) {
        this.usage = usage;
        invalidate();

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(0xffff0000);
        paint.setColor(0xff00ff00);
        String[] u=usage.split("s");
        String[]tmp=u[0].split(",");
        start=Float.valueOf(tmp[0]);
        size=Float.valueOf(tmp[1]);
        for(int i=1;i<u.length;++i){
            tmp=u[i].split(",");
            canvas.drawRect(Float.valueOf(tmp[0])/(size-start)*getWidth(),0,(Float.valueOf(tmp[0])+Float.valueOf(tmp[1]))/(size-start)*getWidth(),getHeight(),paint);
        }
    }
}